package service

import (
	"github.com/beherochuling/beesoft_api/app/helper/net"
	"github.com/beherochuling/beesoft_api/app/model"
	"github.com/gogf/gf/v2/net/ghttp"
	"github.com/gogf/gf/v2/util/gvalid"
)

func Parse(r *ghttp.Request, params interface{}) {
	if err := r.Parse(params); err != nil {
		if v, ok := err.(gvalid.Error); ok {
			errCode := model.ErrorCodeValidFailed
			errMsg := v.FirstError().Error()

			net.NewResponse(r).ResponseException(net.NewException(errCode, errMsg))
		}
		net.NewResponse(r).ResponseBadRequest(err.Error())
	}
}
